﻿namespace Sai.Core.Introspection
{
	public abstract class TypeMember : ITypeMember
	{
		private ObsoleteMarker obsolete;

		protected TypeMember(TypeName typeName) 
		{
			this.TypeName = typeName;
		}

		protected TypeMember(TypeName typeName, ObsoleteMarker marker)
		{
			this.TypeName = typeName;
			this.obsolete = new ObsoleteMarker
			{
				IsEnabled = marker.IsEnabled,
				Reason = marker.Reason
			};
		}

		public TypeName TypeName { get; set; }

		public bool IsObsolete
		{
			get
			{
				if (this.obsolete == null)
				{
					return false;
				}

				return this.obsolete.IsEnabled;
			}
		}

		public string ObsoleteReason
		{
			get
			{
				if (this.obsolete != null
					&& !string.IsNullOrEmpty(this.obsolete.Reason))
				{
					return this.obsolete.Reason;
				}

				return string.Empty;
			}
		}
	}
}
